import * as THREE from "three";

//天空盒
export const skyBox = () => {
  const envTexture = new THREE.CubeTextureLoader().load([
    "/img/skyBox/posx.jpg",
    "/img/skyBox/negx.jpg",
    "/img/skyBox/posy.jpg",
    "/img/skyBox/negy.jpg",
    "/img/skyBox/posz.jpg",
    "/img/skyBox/negz.jpg"
  ]);
  return envTexture;
};

export const createEnvBox = (scene) => {
  let texture = new THREE.TextureLoader().load("/img/bg.jpg");
  let CylinderGeometry = new THREE.CylinderGeometry(50, 50, 25 * Math.PI, 30, 1, true);
  CylinderGeometry.thetaStart = Math.PI / 4;
  let sphereMaterial = new THREE.MeshBasicMaterial({
    map: texture,
    side: THREE.BackSide
  });

  let sphere = new THREE.Mesh(CylinderGeometry, sphereMaterial);
  sphere.position.set(0, 5, 0);

  scene.add(sphere);

  let planeGeometry = new THREE.PlaneGeometry(100, 100);
  let planeTexture = new THREE.TextureLoader().load("/img/yyxx.jpg");
  planeTexture.wrapS = THREE.RepeatWrapping;
  planeTexture.wrapT = THREE.RepeatWrapping;
  planeTexture.repeat.set(3, 3);
  let planeMaterial = new THREE.MeshBasicMaterial({
    map: planeTexture
  });
  let plane = new THREE.Mesh(planeGeometry, planeMaterial);
  plane.rotateX(-Math.PI / 2);
  plane.position.y = -0.001;
  plane.receiveShadow = true;
  scene.add(plane);
};
